package com.wlc.base;

import java.time.LocalDateTime;
import java.util.Calendar;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description 测试
 * @date 2021-08-18 19:36
 */
public class Demo10 {


    public static int method01() throws Exception{
        try {
            int a = 2 / 0;
            throw new Exception("分母不能为0！");

        } catch (Exception e) {
            return 3;
        } finally {
            return 4;
        }
    }

    public static void method02(){
        String s1 = "Programming";
        String s2 = new String("Programming");
        String s3 = "Program";
        String s4 = "ming";
        String s5 = "Program" + "ming";
        String s6 = s3 + s4;
        //System.out.println(s1 == s5);    //true
        //System.out.println(s1 == s2);    //false
        System.out.println(s1 == s6);    //false
        //System.out.println(s1 == s6.intern());    //true
        //System.out.println(s2 == s2.intern());    //false

        System.out.println("s1.intern() = " + s1.intern());
        System.out.println("s5.intern() = " + s5.intern());
        System.out.println("s2.intern() = " + s2.intern());
        System.out.println("s3.intern() = " + s3.intern());
        System.out.println("s6.intern() = " + s6.intern());
    }

    public static void getTime(){
        Calendar cal = Calendar.getInstance();
        System.out.println(cal.get(Calendar.YEAR));
        System.out.println(cal.get(Calendar.MONTH)); // 0 - 11
        System.out.println(cal.get(Calendar.DATE));
        System.out.println(cal.get(Calendar.HOUR_OF_DAY));
        System.out.println(cal.get(Calendar.MINUTE));
        System.out.println(cal.get(Calendar.SECOND));
        // Java 8
        LocalDateTime dt = LocalDateTime.now();
        System.out.println(dt.getYear());
        System.out.println(dt.getMonthValue()); // 1 - 12
        System.out.println(dt.getDayOfMonth());
        System.out.println(dt.getHour());
        System.out.println(dt.getMinute());
        System.out.println(dt.getSecond());


        //
        LocalDateTime localDateTime = dt.withDayOfYear(3);
        System.out.println("localDateTime = " + localDateTime.getDayOfMonth());
    }

    public static void main(String[] args) {
        getTime();
    }
}
